<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %> 

<%
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript" src="<%= ctxPath %>/mt/js/date.js"></script>

<script language="JavaScript">

var resetPagerOffset = true;

//
//
//
function doChannelConfirmDelete() {
  return confirm('<bean-el:message key="ep.channel.confirm.delete" bundle="ep.messages"/>');
}

//
//
//
function doChannelSetStatus(form, status) {
  form.action = "<c:url value="/ep/channelSearchSetOnlineStatus.do"/>";
  if (0 == status) {
    form.action = "<c:url value="/ep/channelSetOfflineStatus.do"/>";
  }
  resetPagerOffset = false;
  form.submit();
}

//
//
//
function setChannelAction(form) {
  form.action = "<c:url value="/ep/channelSearch.do"/>";
}

//
//
//
function setProgramAction(form) {
  form.action = "<c:url value="/ep/programSearch.do"/>";
}

<%@ include file="/mc/common/jsutils.jsp" %>

function validateForm() {
  if (document.epChannelSearchForm.includeLastModifiedDateFrom.checked &&
    document.epChannelSearchForm.includeLastModifiedDateTo.checked) {
    var dateFrom = getDateOnly("epChannelSearchForm", "lastModifiedDateFrom");
    var dateTo = getDateOnly("epChannelSearchForm", "lastModifiedDateTo");
    if (dateTo < dateFrom) {
      alert('<bean:message key="error.search.dateRange" bundle="ep.messages"/>');
      return false;
    }
  }
  if (document.epChannelSearchForm.maxFind.value <= 0) {
    alert('<bean:message key="error.search.maxFound" bundle="ep.messages"/>');
    return false;
  }

<c:if test="${not empty channels}">
  if (resetPagerOffset) {
    document.epChannelSearchForm['pager.offset'].value = 0;
  }

  document.epChannelSearchForm['pager.maxPageItems'].value = 0;
</c:if>
  return true;
}

function checkNumberOnly(e) {
  var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
  if (charCode > 31 && (charCode < 48 || charCode > 57)) {
    return false;
  }
  else {
    return true;
  }
}

</script>

<c:set var="editImg">
<img src="<%= ctxPath %>/ep/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="ep.messages"/>">
</c:set>
<c:set var="offlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOffline" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.setOffline" bundle="ep.messages"/>">
</c:set>
<c:set var="onlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.setOnline" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.setOnline" bundle="ep.messages"/>">
</c:set>
<c:set var="deleteImg">
<img src="<%= ctxPath %>/ep/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.delete" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.delete" bundle="ep.messages"/>">
</c:set>

<html-el:form action="/ep/channelSearch.do" focus="name" onsubmit="return validateForm();">
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
<c:if test="${channels == null}">
      <bean-el:message key="ep.channel.search.page.title" bundle="ep.messages"/>
</c:if>
<c:if test="${channels != null}">
      <bean-el:message key="ep.channel.search.results.page.title" bundle="ep.messages" arg0="${pager.map.count}"/>
</c:if>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@include file="/mc/common/pagetab.jsp" %>

      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="ep.search.criteria" bundle="ep.messages"/></span>
        <span class="right"></span>
      </div>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Search criteria">
        <tr> 
          <td class="label" width="20%">
            <bean-el:message key="ep.label.name" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="80%" colspan="2">
            <html-el:text property="name" maxlength="80" size="31"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%">
            <bean-el:message key="ep.label.type" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="80%" colspan="2">
            <html-el:radio property="type" value="0" onclick="setChannelAction(this.form)"/><bean-el:message key="ep.channel" bundle="ep.messages"/>&nbsp;<html-el:radio property="type" value="1" onclick="setProgramAction(this.form)"/><bean-el:message key="ep.program" bundle="ep.messages"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%">
            <bean-el:message key="ep.label.lastModifiedDate" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="10%" nowrap>
            <html-el:checkbox property="includeLastModifiedDateFrom"/>
            <bean-el:message key="ep.label.from" bundle="ep.messages"/>
          </td>
          <td class="labelField" width="70%" nowrap>
          <bvhtml:date property="lastModifiedDateFrom"
              onChangeMonth="onChangeMonth"
               onChangeYear="onChangeYear"
                    noblank="true"/>
          <a href="JavaScript:datePopup(
            '<html-el:rewrite page="/mt/calendar.do"/>',
            'epChannelSearchForm','lastModifiedDateFrom')"><img
               src="<%= ctxPath %>/ep/images/action/calendar.gif"
             width="22" height="22"
               alt='<bean-el:message key="image.alt.chooseDate" bundle="ep.messages"/>'
             title='<bean-el:message key="image.alt.chooseDate" bundle="ep.messages"/>'
            border="0" align="absmiddle"/></a>
          </td>
        </tr>
        <tr>
          <td class="label" width="20%">&nbsp;</td>
          <td class="labelField" width="10%" nowrap>
            <html-el:checkbox property="includeLastModifiedDateTo"/>
            <bean-el:message key="ep.label.to" bundle="ep.messages"/>
          </td>
          <td class="labelField" width="70%" nowrap>
          <bvhtml:date property="lastModifiedDateTo"
              onChangeMonth="onChangeMonth"
               onChangeYear="onChangeYear"
                    noblank="true"/>
          <a href="JavaScript:datePopup(
            '<html-el:rewrite page="/mt/calendar.do"/>',
            'epChannelSearchForm','lastModifiedDateTo')"><img
               src="<%= ctxPath %>/ep/images/action/calendar.gif"
             width="22" height="22"
               alt='<bean-el:message key="image.alt.chooseDate" bundle="ep.messages"/>'
             title='<bean-el:message key="image.alt.chooseDate" bundle="ep.messages"/>'
            border="0" align="absmiddle"/></a>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%">
            <bean-el:message key="ep.label.status" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="80%" colspan="2">
            <html-el:checkbox property="statusOnline" value="true"/>
            <bean-el:message key="ep.label.online" bundle="ep.messages"/>&nbsp;
            <html-el:checkbox property="statusOffline" value="true"/>
            <bean-el:message key="ep.label.offline" bundle="ep.messages"/>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%">
            <bean-el:message key="ep.label.sortBy" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="80%" colspan="2">
            <html-el:select property="sortBy" size="1">
              <html-el:option value="-1"><bean-el:message key="ep.label.select" bundle="ep.messages"/></html-el:option>
              <html-el:option value="0"><bean-el:message key="ep.label.name" bundle="ep.messages"/></html-el:option>
              <html-el:option value="1"><bean-el:message key="ep.label.lastModifiedDate" bundle="ep.messages"/></html-el:option>
            </html-el:select>
            &nbsp;&nbsp;
            <span class="label">
              <bean-el:message key="ep.label.maxRows" bundle="ep.messages"/>: 
            </span>
            <html-el:select property="maxRows" size="1">
              <html-el:option value="10">10</html-el:option>
              <html-el:option value="20">20</html-el:option>
              <html-el:option value="30">30</html-el:option>
              <html-el:option value="50">50</html-el:option>
              <html-el:option value="100">100</html-el:option>
            </html-el:select>
          </td>
        </tr>
        <tr> 
          <td class="label" width="20%">
            <bean-el:message key="ep.label.maxFind" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="80%" colspan="2">
            <html-el:text property="maxFind" maxlength="4" size="4" onkeypress="return checkNumberOnly(event)"/>
          </td>
        </tr>

      </table>

      <div class="pageButtonWrap" align="right">
        <input type="hidden" name="actionSearch" value="1"/>
        <input hspace="40" type="submit" name="actionSearch" class="pageButton" value="<bean-el:message key="button.showResults" bundle="ep.messages"/>">
      </div>

<c:if test="${channels != null}">

      <br>

        <div class="pageSubtitle">
          <span class="left"><bean-el:message key="ep.label.search.results" arg0="${pager.map.count}" bundle="ep.messages"/></span>

          <span class="right">
          </span>
        </div>

        <div class="pageInstructions">
        </div>

      <input type="hidden" name="channelId"/>
      <input type="hidden" name="ctx.f" value="<c:out value="${requestScope['ctx.f']}"/>"/>

<c:set var="editableCount" value="0"/>
<c:forEach var="breadcrumbs" items="${channels}" varStatus="index">
  <bean:size id="len" name="breadcrumbs"/>
  <c:set var="item" value="${breadcrumbs[len - 1]}"/>
  <c:if test="${item.map.editable}">
    <c:set var="editableCount" value="${editableCount + 1}"/>
  </c:if>
</c:forEach>

<c:set var="buttonDisabled" value=""/>
<c:if test="${editableCount == 0}">
  <c:set var="buttonDisabled">disabled="disabled"</c:set>
</c:if>

<c:if test="${not empty channels}">
      <div class="globalButtonWrap">
        <input type="button" name="selectAllChannels" class="globalButton" value="<bean-el:message key="button.selectAll" bundle="ep.messages"/>"
          onclick="check(this.form.channelIds, this);" <c:out value="${buttonDisabled}"/>>
        <input type="button" class="globalButton" value="<bean-el:message key="button.setOnline" bundle="ep.messages"/>"
          onclick="if (isAnyChecked(this.form.channelIds, '<bean-el:message key="ep.channel.atLeastOne" bundle="ep.messages"/>')) doChannelSetStatus(this.form, 1);" <c:out value="${buttonDisabled}"/>>
        <input type="button" class="globalButton" value="<bean-el:message key="button.setOffline" bundle="ep.messages"/>"
          onclick="if (isAnyChecked(this.form.channelIds, '<bean-el:message key="ep.channel.atLeastOne" bundle="ep.messages"/>')) doChannelSetStatus(this.form, 0);" <c:out value="${buttonDisabled}"/>>
        <input type="button" class="globalButton" value="<bean-el:message key="button.delete" bundle="ep.messages"/>"
          onclick="if (isAnyChecked(this.form.channelIds, '<bean-el:message key="ep.channel.atLeastOne" bundle="ep.messages"/>', '<bean-el:message key="ep.channels.confirm.delete" bundle="ep.messages"/>')) resetPagerOffset = false; doAction('/ep/channelDelete.do', this.form);" <c:out value="${buttonDisabled}"/>>
      </div>
</c:if>

        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
          <tr class="listHeader">
            <th id="Checkboxes">&nbsp;</th>
            <th id="Name" align="left"><bean-el:message key="ep.header.name" bundle="ep.messages"/></th>
            <th id="LastModifiedDate" align="left"><bean-el:message key="ep.header.lastModifiedDate" bundle="ep.messages"/></th>
            <th id="Status" align="left"><bean-el:message key="ep.header.status" bundle="ep.messages"/></th>
            <th id="Actions" align="left" nowrap><bean-el:message key="ep.header.actions" bundle="ep.messages"/></th>
          </tr>

          <!-- results -->

<c:forEach var="breadcrumbs" items="${channels}" varStatus="index">

  <bean:size id="len" name="breadcrumbs"/>
  <c:set var="item" value="${breadcrumbs[len - 1]}"/>

          <c:url var="onlineUrl" value="/ep/channelSearchSetOnlineStatus.do">
            <c:param name="channelId" value="${item.map.id}"/>
            <c:param name="ctx.f" value="${requestScope['ctx.f']}"/>
	  </c:url>
          <c:url var="offlineUrl" value="/ep/channelSetOfflineStatus.do">
            <c:param name="channelId" value="${item.map.id}"/>
            <c:param name="ctx.f" value="${requestScope['ctx.f']}"/>
	  </c:url>
          <c:url var="editUrl" value="/ep/channelEdit.do">
            <c:param name="channelId" value="${item.map.id}"/>
            <c:param name="ctx.f" value="${requestScope['ctx.f']}"/>
	  </c:url>
          <c:url var="deleteUrl" value="/ep/channelDelete.do">
            <c:param name="channelId" value="${item.map.id}"/>
            <c:param name="ctx.f" value="${requestScope['ctx.f']}"/>
	  </c:url>

          <c:choose>
            <c:when test="${(index.count + 1) % 2 == 0}">
              <tr class="listEven">
            </c:when>
            <c:otherwise>
              <tr class="listOdd">
            </c:otherwise>
          </c:choose>
            <td headers="Checkboxes" align="center">
  <c:if test="${item.map.editable}">
              <input type="checkbox" name="channelIds"
                onclick="update(this.form.channelIds, this.form.selectAllChannels);"
                value="<c:out value="${item.map.id}"/>">
  </c:if>
            </td>
            <td headers="Name">
  <c:forEach var="crumb" items="${breadcrumbs}" varStatus="index">
          <c:url var="viewUrl" value="/ep/channelView.do">
            <c:param name="channelId" value="${crumb.map.id}"/>
            <c:param name="ctx.f" value="${requestScope['ctx.f']}"/>
	  </c:url>

          / <a href="<c:out value="${viewUrl}"/>"><c:out value="${crumb.map.name}"/></a>

  </c:forEach>
            </td>

            <td headers="LastModifiedDate"><bean:write name="item" property="lastModTime" formatKey="format.datetime.short" bundle="mc.messages"/></td>

            <td headers="Status">
            <c:choose>
              <c:when test="${item.map.status == 0}">
              <bean-el:message key="ep.label.offline" bundle="ep.messages"/>
              </c:when>
	      <c:otherwise>
	      <bean-el:message key="ep.label.online" bundle="ep.messages"/>
	      </c:otherwise>
            </c:choose>
            </td>

            <td headers="Actions">
  <c:if test="${item.map.editable}">
              <a href="<c:out value="${editUrl}"/>"><c:out value='${editImg}' escapeXml="false"/></a>
              <c:choose>
                <c:when test="${item.map.status == 0}">
                <a href="<c:out value="${onlineUrl}"/>"><c:out value='${onlineImg}' escapeXml="false"/></a>
                </c:when>
                <c:otherwise>
                  <a href="<c:out value="${offlineUrl}"/>"><c:out value='${offlineImg}' escapeXml="false"/></a>
                </c:otherwise>
              </c:choose>
              <a href="<c:out value="${deleteUrl}"/>" onclick="return doChannelConfirmDelete();"><c:out value='${deleteImg}' escapeXml="false"/></a>
  </c:if>
            </td>
          </tr>
</c:forEach>

<c:if test="${empty channels}">
        <tr class="listOdd">
          <td align="center" colspan="5">
            <bean:message key="ep.channels.searchNoFound" bundle="ep.messages"/>
          </td>
        </tr>
</c:if>

        </table>

        <!-- pagination -->
<c:if test="${not empty channels}">
<%@ include file="/mc/common/pager.jsp" %>
</c:if>

</c:if>

    </td>
  </tr>
</table>
</html-el:form>

